using System.Collections.Generic;

using FineCollection.Intf;

using NUnit.Framework;

using FineCollection.Test;


namespace FineCollection.Const
{
    [TestFixture]
    public class CC_test
    {


        #region ListOf()

        [Test]
        public void Test_ListOf0()
        {
            var x1 = CC1.ListOf<byte>();
            x1.IsEmpty._true_();

            var x0 = CC0.ListOf<byte>();
            x0.IsEmpty._true_();
        }    


        [Test]
        public void Test_ListOf1()
        {
            var x1 = CC1.ListOf<byte>(149);

            x1.IsEmpty    ._false_();
            x1.ToArray()  ._array_<byte>(149);
            x1.FirstIndex ._equals_(1);

            var x0 = CC0.ListOf<byte>(149);

            x0.IsEmpty    ._false_();
            x0.ToArray()  ._array_<byte>(149);
            x0.FirstIndex ._equals_(0);
        }


        [Test]
        public void Test_ListOf3()
        {
            var x = CC0.ListOf(111L,222L,333L);

            x.ToArray()  ._array_(111L,222L,333L);
        }


        [Test]
        public void Test_ListOfConstListSameOrigin()
        {
            RCollection<long> x = CC1.ListOf(333L, 444L, 555L, 666L);
            var y = CC1.ListOf(x);

            y ._same_(x);
        }


        [Test]
        public void Test_ListOfConstListAnotherOrigin()
        {
            RCollection<long> x = CC1.ListOf(333L, 444L, 555L, 666L);
            var y = CC0.ListOf(x);

            y.ToArray()._array_(333L, 444L, 555L, 666L);
        }


        #endregion



        #region SortSetOf()

        [Test]
        public void Test_SortSetOf0()
        {
            var x = CC1.SortSetOf<byte>();

            x.IsEmpty._true_();
        }    


        [Test]
        public void Test_SortSetOf1()
        {
            var x = CC1.SortSetOf<byte>(220);

            x.IsEmpty    ._false_();
            x.ToArray()  ._array_<byte>(220);
            x.FirstIndex ._equals_(1);
        }


        [Test]
        public void Test_SortSetOf3()
        {
            var x = CC1.SortSetOf(111L,222L,333L);

            x.ToArray()  ._array_(111L,222L,333L);
        }


        [Test]
        public void Test_SortSetOf3Sort()
        {
            var x = CC1.SortSetOf(777uL, 333uL, 666uL, 222uL);

            x.ToArray()  ._array_(222uL, 333uL, 666uL, 777uL);
        }


        [Test]
        public void Test_SortSetOfSet01()
        {
            var x = CC0.SortSetOf(222L, 333L, 444L);
            var y = CC1.SortSetOf((ROrderSet<long>)x);

            x.FirstIndex ._equals_(0);
            y.FirstIndex ._equals_(1);

            y.ToArray()  ._equals_(x.ToArray()); 
        }


        [Test]
        public void Test_SortSetOfSetIsSame()
        {
            var x1 = CC1.SortSetOf(222L, 333L, 444L);
            var y1 = CC1.SortSetOf((ROrderSet<long>)x1);

            y1 ._same_(x1);

            var x0 = CC0.SortSetOf(222L, 333L, 444L);
            var y0 = CC0.SortSetOf((ROrderSet<long>)x0);

            y0 ._same_(x0);
        }


        #endregion



        #region CONCAT

        [Test]
        public void Test_ConcatBasic()
        {
            var a = CC1.ListOf(111L, 222L, 333L);
            var b = CC1.ListOf(444L, 555L, 666L);

            var c = a + b;

            c.ToArray()._array_(111L, 222L, 333L, 444L, 555L, 666L);
        }


        [Test]
        public void Test_ConcatBasicFirstFirstIndex()
        {
            var a = CC.ListOf(-4, 111L, 222L, 333L);
            var b = CC.ListOf(-7, 444L, 555L, 666L);

            var c = a + b;

            c.FirstIndex ._equals_(-4);
        }


        [Test]
        public void Test_ConcatOneZeroB()
        {
            var a = CC1.ListOf(111L, 222L, 333L);
            var b = CC.ListOf(-1, new long[]{});

            var c = a + b;

            c._same_(a);
        }


        [Test]
        public void Test_ConcatOneZeroA()
        {
            var a = CC.ListOf(-1, new long[] { });
            var b = CC1.ListOf(111L, 222L, 333L);

            var c = a + b;

            c._same_(b);
        }


        [Test]
        public void Test_ConcatBothZero()
        {
            var a = CC.ListOf(-1, new long[] { });
            var b = CC.ListOf(-2, new long[] { });

            var c = a + b;

            c.IsEmpty ._true_();
        }


        #endregion



        #region ToSortMap()

        [Test]
        public void Test_ToSortMap1()
        {
            ulong[] xxx = new ulong[] {11111111, 22222222, 33333333};

            var yyy = xxx.ToSortMap(x => x, x => x.ToString());

            yyy           ._is_not_null_(); 
            yyy.Count     ._equals_(3);
            yyy[11111111] ._equals_("11111111");
            yyy[22222222] ._equals_("22222222");
            yyy[33333333] ._equals_("33333333");
        }


        [Test]
        public void Test_ToSortMap2()
        {
            var uuu = new List<ulong> {11111111, 22222222, 33333333};
            IEnumerable<ulong> xxx = uuu;

            var yyy = xxx.ToSortMap(x => x, x => x.ToString(), 7);

            yyy           ._is_not_null_(); 
            yyy.Count     ._equals_(3);
            yyy[11111111] ._equals_("11111111");
            yyy[22222222] ._equals_("22222222");
            yyy[33333333] ._equals_("33333333");
        }

        #endregion



        #region OLD

        [Test]
        public void Test_UnionBasic1()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf<long>(1111, 2222, 4444);
            ConstSortSet<long> set2 = CC1.SortSetOf<long>(2222, 3333, 5555);

            RRandomSet<long> set3 = CC1.Union(set1, set2);

            set3.Count ._equals_(5);

            set3[1] ._equals_(1111L);
            set3[2] ._equals_(2222L);
            set3[3] ._equals_(3333L);
            set3[4] ._equals_(4444L);
            set3[5] ._equals_(5555L);
        }


        [Test]
        public void Test_Union_OneSetContainsAnotherOne()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf(1111L, 2222L, 3333L, 4444L);
            ConstSortSet<long> set2 = CC1.SortSetOf(2222L, 3333L);

            ConstSortSet<long> set3 = CC1.Union(set1, set2);
            set3 ._same_(set1);

            ConstSortSet<long> set4 = CC1.Union(set2, set1);
            set4 ._same_(set1);
        }


        [Test]
        public void Test_Intersect_NestedLoops_Basic()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf(33L, 100L, 333L);
            ConstSortSet<long> set2 = CC1.SortSetOf(new long[] {11,22,33,44,55,66,77,88,99,
                                                                            111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = CC1.Intersect(set1, set2);

            set3.Count ._equals_(2);

            set3[1]    ._equals_(33);
            set3[2]    ._equals_(333);
        }


        [Test]
        public void Test_Intersect_NestedLoops_Reverted()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf(new long[] {11,22,33,44,55,66,77,88,99,
                                                                            111,222,333,444,555,666,777,888,999});
            ConstSortSet<long> set2 = CC1.SortSetOf(33L, 100L, 333L);

            RRandomSet<long> set3 = CC.Intersect(1, set1, set2);

            set3.Count ._equals_(2);

            set3[1]    ._equals_(33);
            set3[2]    ._equals_(333);
        }


        [Test]
        public void Test_Intersect_NestedLoops_OneInAnother()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf<long>(77, 777);
            ConstSortSet<long> set2 = CC1.SortSetOf<long>(11,22,33,44,55,66,77,88,99,
                                                          111,222,333,444,555,666,777,888,999);

            RRandomSet<long> set3 = CC1.Intersect(set1, set2);
            set3  ._same_(set1);

            RRandomSet<long> set4 = CC1.Intersect(set2, set1);
            set4  ._same_(set1);
        }


        [Test]
        public void Test_Intersect_NestedLoops_127_28()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf<long>(11,22,33,44,55,66,77,88,99,
                                                          111,222,333,444,555,666,777);
            ConstSortSet<long> set2 = CC1.SortSetOf<long>(22, 888);

            RRandomSet<long> set3 = CC1.Intersect(set1, set2);

            set3.Count  ._equals_(1);

            set3[1]     ._equals_(22); 
        }


        [Test]
        public void Test_Intersect_NestedLoops_2379_17()
        {
            ConstSortSet<long> set1 = CC1.SortSetOf<long>(22,33,44,55,66,77,88,99,
                                                          111,222,333,444,555,666,777,888,999);
            ConstSortSet<long> set2 = CC1.SortSetOf<long>(11, 777);

            RRandomSet<long> set3 = CC.Intersect(1, set1, set2);

            set3.Count    ._equals_(1);

            set3[1]       ._equals_(777);
        }


        /*
        [Test]
        public void Test_Intersect_NestedLoops_OneLowerAnother()
        {
            ConstSortSet<long> set1 = new ConstSortSet<long>(3,7);
            ConstSortSet<long> set2 = new ConstSortSet<long>(1, new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = CC.Intersect(1, set1, set2);

            Assert.IsTrue(set3.IsEmpty);
            Assert.AreSame(ConstOrderZero<long>.zero, set3);
        }


        [Test]
        public void Test_Intersect_NestedLoops_OneAfterAnother()
        {
            ConstSortSet<long> set1 = new ConstSortSet<long>(777777,7777777);
            ConstSortSet<long> set2 = new ConstSortSet<long>(1, new long[] {11,22,33,44,55,66,77,88,99,
                111,222,333,444,555,666,777,888,999});

            RRandomSet<long> set3 = CC.Intersect(1, set1, set2);

            Assert.IsTrue(set3.IsEmpty);
            Assert.AreSame(ConstOrderZero<long>.zero, set3);
        }
        */


        [Test]
        public void Test_Difference_Basic()
        {
            var set1 = CC1.SortSetOf(33, 44, 55);
            var set2 = CC1.SortSetOf(33, 55, 77);
            var expDiff = CC1.SortSetOf(44);

            var gotDiff = CC1.Difference(set1, set2);

            CC.AreEqual<int,int,int>(expDiff, gotDiff) ._true_();
        }


        [Test]
        public void Test_Difference_MinuendLessThanSubtrahend()
        {
            var set1 = CC1.SortSetOf(33, 55);
            var set2 = CC1.SortSetOf(22, 33, 44, 55);

            var gotDiff = CC1.Difference(set1, set2);

            gotDiff.IsEmpty ._true_();
        }


        /*
        [Test]
        public void Test_Difference_MinuendAsIs()
        {
            var set1 = new ConstSortSet<int>(33, 55);
            var set2 = new ConstOrderZero<int>();

            var gotDiff = CC.Difference(set1, set2);

            Assert.AreSame(set1, gotDiff);
        }
        */

        #endregion

    }
}